public class Demo12 {
    private static int result = 0;

    public static void main(String[] args) {
        Thread mainThread = Thread.currentThread();
        Thread t = new Thread(() -> {
            // 打印结果
            try {
                mainThread.join();
                System.out.println("计算结束: " + result);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        t.start();

        int sum = 0;
        for (int i = 1; i <= 1000; i++) {
            sum += i;
        }
        result = sum;
    }
}
